<template>
  <el-row :gutter="10">
    <el-col class="right-main pain" :lg="24">
      <el-row class="list">
        <div v-if="datas.length!=0">
          <template v-for="(v,index) in datas">
            <el-col :span="4" class="list-li" :key="index">
              <el-row>
                  <img :src="fm" alt />
                  <p class="name">
                     {{v.title}}
                  </p>
                  <p class="pauthor">
                    {{!v.author?'暂无作者':v.author}}
                  </p>
              </el-row>
            </el-col>
          </template>
        </div>

        <div v-else>
          <template v-show="datas.length=0">
            <p style="text-align:center;">暂无数据</p>
          </template>
        </div>
        <el-col class="total">
          <el-pagination
            @current-change="handleCurrentChange"
            background
            layout="prev, pager, next"
            size="10"
            :total="total"
          ></el-pagination>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>
<script>
import { videoList, operation, removeFavorite } from "@/api/page";
import { getToken1 } from "@/utils/auth";
import store from "../../store";
export default {
  name: "recommend",
  data() {
    return {
      value: 5,
      fm: require("@/assets/index/fengmian.png"),
      collection: require("@/assets/index/collection.png"),
      liulan: require("@/assets/index/liulan.png"),
      pinglun: require("@/assets/index/pinglun.png"),
      activeName: "first",
      collects: [],
      datas: [],
      form: {
        page: null,
        page_size: 10,
        search: "",
        category_id: null,
        order: "asc",
        type: 2,
      },
      total: null,
      state: "state",
    };
  },
  created() {
    this.dataList();
    this.token = getToken1();
  },
  methods: {
    // 重新获取数据
    dataList() {
      this.listLoading = true;
      let params = this.form;
      videoList(params).then((response) => {
        this.datas = response.data.data;
        this.collects = response.data.collection;
        this.total = response.total;
        this.listLoading = false;
      });
    },
    // 验证权限
    role() {
      if (!this.token) {
        this.$confirm("额。。。，您好像没有权限，是否去登录?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.$router.push("/login");
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "您继续浏览吧",
            });
            return false;
          });
      }
    },
    select(index) {
      this.active = index;
    },
    link() {
      this.$router.push("/index/news");
      // this.componentName.name='Reading'
    },
    handleClick(tab, event) {
      this.form.sort = tab.name;
      this.dataList();
    },
    choose(index) {
      this.activeId = this.category[index].category_id;
      this.form.category_id = this.category[index].category_id;
      this.dataList();
    },
    // 操作收藏
    collections(index) {
      this.role();
      if (this.token) {
        if (this.collects.includes(this.datas[index].file_id)) {
          this.removeFavorites(index);
        } else {
          this.operations(index);
        }
      }
    },
    // 取消收藏
    removeFavorites(index) {
      let params = {
        id: this.datas[index].file_id,
        type: 2,
      };
      removeFavorite(params).then((response) => {
        if (response.code == 1) {
          this.$message({
            type: "success",
            message: "取消成功",
          });
          this.dataList();
        }
      });
    },
    //收藏
    operations(index) {
      let params = {
        id: this.datas[index].file_id,
        type: 2,
        classify: 1,
      };
      operation(params).then((response) => {
        if (response.code == 1) {
          this.$message({
            type: "success",
            message: "收藏成功",
          });
          this.dataList();
        }
      });
    },
    //  评论
    pl(index) {},
    // 分页
    handleCurrentChange(val) {
      this.form.page = val;
      this.dataList();
    },
    select(index) {
      this.active = index;
      console.log(index);
    },
  },
};
</script>
<style lang="scss" scoped>
.table-content {
  height: 570px;
  overflow: hidden;
}
.right-main {
  position: relative;
  padding-left: 25px !important;
}
.classification {
  background: rgba(89, 186, 189, 1);
  border-radius: 10px;
  text-align: center;
  padding: 10px;
  color: rgba(255, 255, 255, 1);
}
.title {
  font-size: 26px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: rgba(255, 255, 255, 1);
  text-align: left;
}
.news {
  padding: 30px 0;
}

.tab {
  text-align: right;
  margin-top: 0px;
  border-right: 1px solid #e4e4e4;
  li {
    display: inline-block;
    padding: 12px 30px;
    border-left: 1px solid #e4e4e4;
    border-bottom: 1px solid #e4e4e4;
    font-size: 20px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: rgba(79, 79, 79, 1);
    cursor: pointer;
  }
  li:hover {
    color: #1ca2a7 !important;
  }
  .active {
    color: #1ca2a7 !important;
    border-bottom: 0px solid #ddd;
  }
}
.point {
  span {
    float: left;
  }
}
.info {
  position: relative;
  > span {
    position: absolute;
    left: 0;
    top: 6px;
  }
}
.name {
 font-size:22px;
font-family:Microsoft YaHei;
font-weight:300;
color:rgba(20,104,108,1);
  margin-top: 0;
  padding: 10px 0 10px 0;
}
.icon {
  padding-top: 40px;
}
.list {
  padding-top: 30px;
  img {
    margin-left: 0;
  }
}
.list-li {
  padding-bottom: 30px;
}
.icon {
  font-size: 18px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: rgba(142, 142, 142, 1);
  img {
    margin-right: 10px;
  }
}
.total {
  text-align: center;
  padding: 100px 0 50px 0;
}
.state {
  color: #1ca2a7;
}
</style>
<style lang="scss">
ul,
li {
  padding: 0;
}

.pain .el-tabs__item.is-active {
  font-size: 22px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: rgba(37, 37, 37, 1);
}
.pain .el-tabs__active-bar {
  background-color: #1ca2a7;
}
.pain .el-tabs__item {
  height: 50px;
  line-height: normal;
}
.pain .el-tabs__header {
  margin: 0;
}
.info .el-button {
  border: none;
  padding: 0;
  width: 100%;
  line-height: 30px;
  white-space: normal;
  text-align: left;
  text-indent: 45px;
  span {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    font-size: 20px;
    color: #4f4f4f;
  }
}
.info {
  .el-button:hover {
    background: none;
  }
}
.name {
  .el-button {
    width: 130px;
    height: 42px;
    background: rgba(28, 162, 167, 1);
    border-radius: 4px;
    font-size: 20px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: rgba(255, 255, 255, 1);
  }
}
.total .el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #1ca2a7 !important;
  cursor: default;
}
.total .el-pagination.is-background .el-pager li:not(.disabled):hover {
  color: #1ca2a7;
}
</style>